package com.innoking.docsys.logger.service.impl;

import com.innoking.docsys.log.module.LoggerVO;
import com.innoking.docsys.logger.dao.master.MasterLogUserLoginDao;
import com.innoking.docsys.logger.dto.LogDocUserLogin;
import com.innoking.docsys.logger.service.LoggerCall;
import com.innoking.docsys.logger.utils.LoggerUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author sunq
 * 策略模式处理log业务
 */
public class LoggerLoginCallImpl  implements LoggerCall {

    @SuppressWarnings(value={"null"})
    public   RedisTemplate redisTemplate;

    @SuppressWarnings(value={"null"})
    public MasterLogUserLoginDao masterLogUserLoginDao;

    public LoggerLoginCallImpl(RedisTemplate redis,MasterLogUserLoginDao dao) {
        this.redisTemplate=redis;
        this.masterLogUserLoginDao=dao;
    }

    @Override
    public void addLogger(LoggerVO vo) {

        redisTemplate.opsForList().leftPush(LoggerUtils.LOGGER_LOGIN,vo);
        LogDocUserLogin dto=new LogDocUserLogin();
        BeanUtils.copyProperties(vo,dto,"targetContent");
        masterLogUserLoginDao.insertLoginLog(dto);

    }
}